// 这一层负责和数据库打交道
const articleModel = require("./models/articleModel");

// 新增博客
module.exports.createArticleDao = async function (data) {
  return await articleModel.create(data);
};

// 查询根据pk查询
module.exports.findByPkArticleDao = async function (id) {
  return await articleModel.findByPk(id);
};

// 分页查询
module.exports.findArticleByPageDao = async function ({ condition }) {
  return await articleModel.findAndCountAll({
    where: {
      title: {
        [Op.like]: "foo%",
      },
    },
    offset: 10,
    limit: 2,
  });
};

module.exports.updateArticleDao = async function (id, data) {
  return await articleModel.update(data, {
    where: {
      id: id,
    },
  });
};

module.exports.deleteArticleDao = async function (id) {
  return await articleModel.destroy({
    where: {
      id,
    },
  });
};
